package edu.mis.modules.room;

import java.util.List;

import com.jfinal.plugin.activerecord.Record;


import edu.mis.model.Room;


/**
 * 用户服务类
 *
 */
public class RoomService {
	
	
	
	/**
	 * 修改密码
	 * @param user
	 * @return
	 */
	public boolean updatePassword(int id,String newRoomName,String newRoomSize,String newRoomPhoto,String newRoomState){
		Room room = findRoomById(id);
		room.setRoomName(newRoomName);
		room.setRoomSize(newRoomSize);
		room.setRoomPhoto(newRoomPhoto);
		room.setRoomState(newRoomState);
		return room.update();
	}
	
	public boolean saveRoom(Room room){  //service命名建议完整，见名知意。如此处的saveBlog，参数尽量用对象
		return room.save();
	}
	
	/**
	 * 根据ID得到用户
	 * @param id
	 * @return
	 */
	public Room findRoomById(int id) {
		return Room.dao.findById(id);
	}
	
	/**
	 * 查询所有用户
	 * @return
	 */
	public List<Room> findAllRoom(){
		return Room.dao.findAll();
	}
	/**
	 * 查询所有商品及其权限
	 * @return
	 */
	public List<Record> findAllRoomWithRoomtype(){
		return Room.dao.findAllRecord();
	}

	/**
	 * 用户授权
	 * @param id
	 * @param roleId
	 * @return
	 */
	public boolean roomAuthorize(int id, int typeId) {
		Room room = findRoomById(id);
		room.setTypeId(typeId);
		return room.update();
	}
}
